<?php

/*----------------------------------------------------------------------------
 *  define IgnitionBase's version
 *----------------------------------------------------------------------------
 */
define( 'IB_Version', '0.1' );

/*----------------------------------------------------------------------------
 *  define system-wide constants
 *----------------------------------------------------------------------------
 */

define( 'DS', DIRECTORY_SEPARATOR );
define( 'NS', '::' );
define( 'EXT', '.'.pathinfo( __FILE__, PATHINFO_EXTENSION ) );
define( 'SELF', pathinfo( __FILE__, PATHINFO_BASENAME ) );
define( 'INDEXPATH', __FILE__ );
define( 'BASEPATH', dirname( __FILE__ ) . DS );
define( 'SYSPATH', BASEPATH . 'system' . DS );
define( 'MODULEPATH', BASEPATH . 'modules' . DS );

/*----------------------------------------------------------------------------
 *  sets up pre-init error and exception handlers because error component
 *  has not been set up yet
 *----------------------------------------------------------------------------
 */
error_reporting( E_ALL );

function pre_init_error_handler( $severity, $message, $filepath, $line )
{
    ?>
    <h1>IgnitionBase Pre-init Error:</h1>
    <?=$severity?> --> <?=$message?> in <?=$filepath?> on line <?=$line?>
    <?php
    die( );
}

function pre_init_exception_handler( $e )
{
    ?>
    <h1>IgnitionBase Pre-init Error:</h1>
    Exception --> <?=$e->getMessage()?> in <?=$e->getFile()?> on line <?=$e->getLine()?>
    <?php
    die( );
}

set_error_handler( 'pre_init_error_handler' );
set_exception_handler( 'pre_init_exception_handler' );

/*----------------------------------------------------------------------------
 *  simple class includer
 *----------------------------------------------------------------------------
 */
function ib_include( $classname )
{
    require_once BASEPATH . str_replace(NS, DS, $classname) . EXT;
}

ib_include( 'system::IgnitionBase' );

/*----------------------------------------------------------------------------
 *  instantiate IgnitionBase
 *----------------------------------------------------------------------------
 */
$IB = IgnitionBase::get_instance( );

/*----------------------------------------------------------------------------
 *  setup IgnitionBase sub-systems (note: they are loaded in order)
 *----------------------------------------------------------------------------
 */
//$IB->set_path( IgnitionBase::SUBSYSTEM, 'system::subsystems' );

$subsystems['profiler'] = 'Profiler';
$subsystems['error'] = 'ErrorHandler';
$subsystems['router'] = 'Router';
$subsystems['render'] = 'Render';

/*----------------------------------------------------------------------------
 *  call the requested controller
 *----------------------------------------------------------------------------
 */
$IB->process( $subsystems );

/*-----------------------------------------------------------------------------
 *  End of index.php
 *  index.php
 *-----------------------------------------------------------------------------
 */